package jp.co.yamcha.common.aop;

import java.io.Serializable;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;

@MyInterceptorLog @Interceptor
public class YamchaLoggingInterceptor implements Serializable {
    private static final Logger LOG = Logger.getLogger(YamchaLoggingInterceptor.class.getName());

    @AroundInvoke
    public Object methodLog(InvocationContext ic) throws Exception {
        //TimeUnit.MILLISECONDS.toSeconds(
        //Date startTime = System.currentTimeMillis();
        LOG.log(Level.INFO, "[start]" + ic.getTarget().getClass().getSimpleName()+ "#" + ic.getMethod().getName());
        try {
            return ic.proceed();
        } finally {
            LOG.log(Level.INFO, "[end  ]" + ic.getTarget().getClass().getSimpleName() + "#" + ic.getMethod().getName());
        }
    }
}
